package org.linlinjava.litemall.db.service.impl;

import org.linlinjava.litemall.db.dao.LitemallDeliveryNoticeMapper;
import org.linlinjava.litemall.db.domain.LitemallDeliveryNotice;
import org.linlinjava.litemall.db.domain.LitemallDeliveryNoticeExample;
import org.linlinjava.litemall.db.service.LitemallDeliveryNoticeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class LitemallDeliveryNoticeServiceImpl implements LitemallDeliveryNoticeService {
    @Resource
    private LitemallDeliveryNoticeMapper deliveryNoticeMapper;

    @Override
    public List<LitemallDeliveryNotice> queryList() {
        LitemallDeliveryNoticeExample example = new LitemallDeliveryNoticeExample();
        example.or().andDeletedEqualTo(false).andStatusEqualTo(true);
        example.setOrderByClause("sort_order ASC");
        return deliveryNoticeMapper.selectByExample(example);
    }

    @Override
    public LitemallDeliveryNotice queryById(Integer id) {
        return deliveryNoticeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int add(LitemallDeliveryNotice notice) {
        notice.setAddTime(LocalDateTime.now());
        notice.setUpdateTime(LocalDateTime.now());
        return deliveryNoticeMapper.insertSelective(notice);
    }

    @Override
    public int update(LitemallDeliveryNotice notice) {
        notice.setUpdateTime(LocalDateTime.now());
        return deliveryNoticeMapper.updateByPrimaryKeySelective(notice);
    }

    @Override
    public int delete(Integer id) {
        LitemallDeliveryNotice notice = new LitemallDeliveryNotice();
        notice.setId(id);
        notice.setDeleted(true);
        notice.setUpdateTime(LocalDateTime.now());
        return deliveryNoticeMapper.updateByPrimaryKeySelective(notice);
    }
} 